package com.hhj.sharding.sphere.demo.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhj.sharding.sphere.demo.model.OrderParamVO;
import com.hhj.sharding.sphere.demo.model.UserParamVO;
import com.hhj.sharding.sphere.demo.model.entity.Order;
import com.hhj.sharding.sphere.demo.model.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author HHJ
 * @since 2024-05-21
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("<script>" +

            " SELECT RE.* FROM t_user RE " +
            " WHERE RE.is_deleted = 0 " +

            " <if test=\"req.id != null \"> " +
            " AND RE.id = #{req.id}" +
            " </if> " +

            " <if test=\"req.userName != null \"> " +
            " AND RE.user_name = #{req.userName}" +
            " </if> " +

            " <if test=\"req.userEmail != null \"> " +
            " AND RE.user_email = #{req.userEmail}" +
            " </if> " +

            " <if test=\"req.userPhone != null \"> " +
            " AND RE.user_phone = #{req.userPhone}" +
            " </if> " +

            " ORDER BY RE.id DESC" +

            "</script>")
    List<User> findList(@Param("page") Page page, @Param("req") UserParamVO req);
}
